﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsFormsApplication1
{
    class RandomGen
    {
        private int iRand = 0;
        Random oRand = new Random();

        public int Generate()
        {
            int iii = oRand.Next(0, 16666);
            double d = oRand.NextDouble();
            //iRand++;

            int i = (int)(iii * 100 * DateTime.Now.Ticks * iRand++) % 17;
            if (i > 11)
                i = i /2;
            if (i == 6)
            {
                iii = oRand.Next(0, 6);
                i = (int)(iii * DateTime.Now.Ticks * iRand++) % 7;
                if (i == 6)
                    i = oRand.Next(0, 6);
            }
            if (i == 4)
            {
                //i = (int)(iii * 100 * DateTime.Now.Ticks * iRand++) % 5;
                //if (i == 4)
                //    i = oRand.Next(3,4);
            }
            if (i < 0)
            {
                if (d % 3 == 0)
                    i = 0;
                else
                    i = -i;
            }
            if (i > 6)
                i = i%(oRand.Next(1,5));
            if (i == 5)
                i = 0;
            if (i == 3)
            {
                i = oRand.Next(1,3);
            }
            
            return i;
        }
    }
}
